/*
 * TableroM2.java
 *
 * Created on 2 de junio de 2009, 04:36 AM
 */
package gui;

import conexion.SocketClient;
import conexion.SocketListener;
import java.awt.Color;
import java.util.ArrayList;
import javax.swing.ImageIcon;
import javax.swing.JOptionPane;
import mundo.Baraja;
import mundo.Carta;

/**
 *
 * @author  Arquitectura
 */
public class TableroM2_1_1 extends javax.swing.JFrame implements SocketListener {

    private SocketClient socket;
    private ArrayList<Carta> todas;
    private ArrayList<Carta> anfitrion;
    private ArrayList<Carta> jugador1;
    private ArrayList<Carta> jugada;
    private Double puntosAlfitrion;
    private Double puntosJugador1;
    private int empates;
    private InformeJuego ij;
    private Baraja baraja;
    private String LetraCarta;
    private ArrayList<String> jugadores;
    private ArrayList<String> puntajes;
    private int conCuartetosA;
    private int conCuartetosJ;
    private Home gc;

    /** Creates new form TableroM2 */
    public TableroM2_1_1(Home gc) {
        initComponents();
        this.gc=gc;
        xPnlFondo pnlFondo = new xPnlFondo(17);
        this.add(pnlFondo);
        this.pack();
        this.setSize(800, 635); //El 635 depende (alto) depende del Skin usado.
        this.setLocationRelativeTo(null);


        this.todas = new ArrayList<Carta>();
        this.anfitrion = new ArrayList<Carta>();
        this.jugador1 = new ArrayList<Carta>();
        this.jugada = new ArrayList<Carta>();
        this.puntosAlfitrion = 0.0;
        this.puntosJugador1 = 0.0;
        this.empates = 0;
        this.baraja = new Baraja();
        this.todas= baraja.getBaraja();
        this.LetraCarta = new String();
        this.jugadores = new ArrayList();
        this.puntajes = new ArrayList();
        this.conCuartetosA = 0;
        this.conCuartetosJ = 0;
        this.setVisible(true);
        //this.Iniciar();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jlJugador = new javax.swing.JLabel();
        jlTurnoActual = new javax.swing.JLabel();
        jProgressBar1 = new javax.swing.JProgressBar();
        jPanel1 = new javax.swing.JPanel();
        jlNumero = new javax.swing.JLabel();
        jrPedir = new javax.swing.JRadioButton();
        jrBajarse = new javax.swing.JRadioButton();
        jcNumero = new javax.swing.JComboBox();
        jPanel2 = new javax.swing.JPanel();
        jbRealizar = new javax.swing.JButton();
        jbConsultar = new javax.swing.JButton();
        jbAbandonar = new javax.swing.JButton();
        jlp = new javax.swing.JLabel();
        jlPuntos = new javax.swing.JLabel();
        jPanel3 = new javax.swing.JPanel();
        CartaMuestra = new javax.swing.JLabel();
        jlAnterior = new javax.swing.JLabel();
        jlSiguiente = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        jlJugador.setText("Jugador1");

        jlTurnoActual.setText("jLabel1");

        jPanel1.setOpaque(false);

        jlNumero.setText("Numero:");

        jrPedir.setText("Pedir Carta");
        jrPedir.setBorder(null);
        jrPedir.setEnabled(false);
        jrPedir.setOpaque(false);
        jrPedir.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jrPedirActionPerformed(evt);
            }
        });

        jrBajarse.setText("Bajarase");
        jrBajarse.setBorder(null);
        jrBajarse.setEnabled(false);
        jrBajarse.setOpaque(false);
        jrBajarse.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jrBajarseActionPerformed(evt);
            }
        });

        jcNumero.setModel(new javax.swing.DefaultComboBoxModel(new String[] { " ", "1", "2", "3", "4", "5", "6", "7", "8" }));

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jlNumero)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(jrPedir)
                        .addGap(2, 2, 2)
                        .addComponent(jrBajarse))
                    .addComponent(jcNumero, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jcNumero, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jlNumero))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jrPedir)
                    .addComponent(jrBajarse))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jPanel2.setOpaque(false);

        jbRealizar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/gui/BTN_realizarJugada.png"))); // NOI18N
        jbRealizar.setBorder(null);
        jbRealizar.setBorderPainted(false);
        jbRealizar.setContentAreaFilled(false);
        jbRealizar.setEnabled(false);
        jbRealizar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbRealizarActionPerformed(evt);
            }
        });

        jbConsultar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/gui/BTN_ConsultarInforme.png"))); // NOI18N
        jbConsultar.setBorder(null);
        jbConsultar.setBorderPainted(false);
        jbConsultar.setContentAreaFilled(false);
        jbConsultar.setEnabled(false);
        jbConsultar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbConsultarActionPerformed(evt);
            }
        });

        jbAbandonar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/gui/BTN_cancelar.png"))); // NOI18N
        jbAbandonar.setBorder(null);
        jbAbandonar.setBorderPainted(false);
        jbAbandonar.setContentAreaFilled(false);
        jbAbandonar.setEnabled(false);
        jbAbandonar.setRolloverIcon(new javax.swing.ImageIcon(getClass().getResource("/gui/BTN_cancelar_roll.png"))); // NOI18N
        jbAbandonar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbAbandonarActionPerformed(evt);
            }
        });

        jlp.setText("Puntos:");

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jlp)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jlPuntos, javax.swing.GroupLayout.PREFERRED_SIZE, 117, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jbAbandonar)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jbConsultar)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jbRealizar, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addGap(26, 26, 26)
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jbRealizar)
                            .addComponent(jbAbandonar)
                            .addComponent(jbConsultar)))
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addGap(28, 28, 28)
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jlp)
                            .addComponent(jlPuntos, javax.swing.GroupLayout.PREFERRED_SIZE, 14, javax.swing.GroupLayout.PREFERRED_SIZE))))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jPanel3.setOpaque(false);

        CartaMuestra.setPreferredSize(new java.awt.Dimension(34, 14));

        jlAnterior.setIcon(new javax.swing.ImageIcon(getClass().getResource("/gui/BTN_previous.png"))); // NOI18N
        jlAnterior.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jlAnteriorMouseClicked(evt);
            }
        });

        jlSiguiente.setIcon(new javax.swing.ImageIcon(getClass().getResource("/gui/BTN_next.png"))); // NOI18N
        jlSiguiente.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jlSiguienteMouseClicked(evt);
            }
        });

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel3Layout.createSequentialGroup()
                .addGap(47, 47, 47)
                .addComponent(jlAnterior)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 103, Short.MAX_VALUE)
                .addComponent(CartaMuestra, javax.swing.GroupLayout.PREFERRED_SIZE, 227, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(91, 91, 91)
                .addComponent(jlSiguiente)
                .addGap(48, 48, 48))
        );
        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addContainerGap(22, Short.MAX_VALUE)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(CartaMuestra, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 340, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel3Layout.createSequentialGroup()
                        .addComponent(jlSiguiente)
                        .addGap(109, 109, 109))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel3Layout.createSequentialGroup()
                        .addComponent(jlAnterior)
                        .addGap(110, 110, 110))))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jPanel3, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(110, 110, 110)
                        .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(jProgressBar1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap())
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addGap(190, 190, 190)
                .addComponent(jlJugador)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 315, Short.MAX_VALUE)
                .addComponent(jlTurnoActual, javax.swing.GroupLayout.PREFERRED_SIZE, 53, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(189, 189, 189))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jProgressBar1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(60, 60, 60)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jlTurnoActual)
                    .addComponent(jlJugador))
                .addGap(18, 18, 18)
                .addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 9, Short.MAX_VALUE)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap())
        );

        java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
        setBounds((screenSize.width-800)/2, (screenSize.height-600)/2, 800, 600);
    }// </editor-fold>//GEN-END:initComponents

    private void jbAbandonarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbAbandonarActionPerformed
        // TODO add your handling code here:
        socket.send("3");
        this.dispose();
        this.gc.setVisible(true);
        try {
            this.ij.dispose();
        } catch (Exception e) {
        }
    }//GEN-LAST:event_jbAbandonarActionPerformed

    private void jlSiguienteMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jlSiguienteMouseClicked
        // TODO add your handling code here:        

        socket.send("1"); //para recibir la siguiente carta


    }//GEN-LAST:event_jlSiguienteMouseClicked

    private void jlAnteriorMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jlAnteriorMouseClicked
        // TODO add your handling code here:

        socket.send("2"); //para recibir la carta anterior
    }//GEN-LAST:event_jlAnteriorMouseClicked

    private void jbConsultarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbConsultarActionPerformed
        // TODO add your handling code here:
        this.jugadores.add(this.jlJugador.getText());
        this.jugadores.add("Anfitrion");
        this.puntajes.add("" + puntosJugador1);
        this.puntajes.add("" + puntosAlfitrion);
        ij = new InformeJuego(jugadores, puntajes, empates);
        ij.setVisible(true);

    }//GEN-LAST:event_jbConsultarActionPerformed

    private void jbRealizarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbRealizarActionPerformed
        // TODO add your handling code here:
        if (this.conCuartetosA + this.conCuartetosJ == 8) {
            if (conCuartetosA == conCuartetosJ) {
                if (this.puntosJugador1 == this.puntosAlfitrion) {
                    JOptionPane.showMessageDialog(null, "EMPATE", "INFORMACION", JOptionPane.INFORMATION_MESSAGE);
                    socket.send("6");
                    this.dispose();
                    this.gc.setVisible(true);
                } else if (this.puntosAlfitrion > this.puntosJugador1) {
                    JOptionPane.showMessageDialog(null, "PERDISTE", "INFORMACION", JOptionPane.INFORMATION_MESSAGE);
                    socket.send("7");
                    this.dispose();
                    this.gc.setVisible(true);
                } else {
                    JOptionPane.showMessageDialog(null, "GANASTE", "INFORMACION", JOptionPane.INFORMATION_MESSAGE);
                    socket.send("8");
                    this.dispose();
                    this.gc.setVisible(true);
                }
            } else if (conCuartetosA > conCuartetosJ) {
                JOptionPane.showMessageDialog(null, "PERDISTE", "INFORMACION", JOptionPane.INFORMATION_MESSAGE);
                socket.send("7");
                this.dispose();
                this.gc.setVisible(true);
            } else if (conCuartetosA < conCuartetosJ) {
                JOptionPane.showMessageDialog(null, "GANASTE", "INFORMACION", JOptionPane.INFORMATION_MESSAGE);
                socket.send("8");
                this.dispose();
                this.gc.setVisible(true);
            }
        }
        //boolean valido = false;
        if (this.jrBajarse.isSelected() == true) {
            if (this.jcNumero.getSelectedIndex() == 0) {
                JOptionPane.showMessageDialog(null, "Elija el numero del cuarteto", "INFORMACION", JOptionPane.INFORMATION_MESSAGE);
            } else {
                socket.send("A1" + this.jcNumero.getSelectedIndex());

            }
        } else if (this.jrPedir.isSelected() == true) {
            if (this.jcNumero.getSelectedIndex() == 0) {
                JOptionPane.showMessageDialog(null, "Elija el numero de la carta a solicitar", "INFORMACION", JOptionPane.INFORMATION_MESSAGE);
            } else {
                socket.send("9" + this.jcNumero.getSelectedIndex());
                this.jbRealizar.setEnabled(false);
                this.jrBajarse.setEnabled(false);
                this.jrPedir.setEnabled(false);
                this.jcNumero.setEnabled(false);
            }
        }

    }//GEN-LAST:event_jbRealizarActionPerformed

    private void jrPedirActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jrPedirActionPerformed
        // TODO add your handling code here:
        this.jrBajarse.setSelected(false);
    }//GEN-LAST:event_jrPedirActionPerformed

    private void jrBajarseActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jrBajarseActionPerformed
        // TODO add your handling code here:
        this.jrPedir.setSelected(false);
}//GEN-LAST:event_jrBajarseActionPerformed

    public void Iniciar(String host,int puerto) {
        int p = 0;
        socket = new SocketClient(host, puerto, this);
        socket.send("hola soy cliente");
        this.jProgressBar1.setIndeterminate(true);
        this.jlPuntos.setText("0.0");
        System.out.println(puerto);
    }

    /**
     * @param args the command line arguments
     *//*
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                new TableroM2_1_1().setVisible(true);
            }
        });
    }*/
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JLabel CartaMuestra;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JProgressBar jProgressBar1;
    private javax.swing.JButton jbAbandonar;
    private javax.swing.JButton jbConsultar;
    private javax.swing.JButton jbRealizar;
    private javax.swing.JComboBox jcNumero;
    private javax.swing.JLabel jlAnterior;
    private javax.swing.JLabel jlJugador;
    private javax.swing.JLabel jlNumero;
    private javax.swing.JLabel jlPuntos;
    private javax.swing.JLabel jlSiguiente;
    private javax.swing.JLabel jlTurnoActual;
    private javax.swing.JLabel jlp;
    private javax.swing.JRadioButton jrBajarse;
    private javax.swing.JRadioButton jrPedir;
    // End of variables declaration//GEN-END:variables

    public void receiveData(String data) {
        if (data.substring(0, 1).equalsIgnoreCase("1")) // la carta
        {
            //this.jtCarta.setText(data.substring(1));
        } else if (data.substring(0, 1).equalsIgnoreCase("2")) {
            this.jlJugador.setText(data.substring(1));
        } else if (data.substring(0, 1).equalsIgnoreCase("3")) {
            this.jlTurnoActual.setText("Anfitrión");
            this.jlTurnoActual.setForeground(Color.RED);
            JOptionPane.showMessageDialog(null, "Empieza Anfitrión", "TURNO", JOptionPane.INFORMATION_MESSAGE);
            this.jbRealizar.setEnabled(false);
            this.jcNumero.setEnabled(false);
            //this.jcCaracteristica.setEnabled(false);
            this.jbAbandonar.setEnabled(true);
            this.jbConsultar.setEnabled(true);
            this.jcNumero.setEnabled(false);
            this.jrBajarse.setEnabled(false);
            this.jrPedir.setEnabled(false);
        } else if (data.substring(0, 1).equalsIgnoreCase("4")) {
            this.jlTurnoActual.setText("Jugador1");
            this.jlTurnoActual.setForeground(Color.RED);
            JOptionPane.showMessageDialog(null, "Empieza Jugador1", "TURNO", JOptionPane.INFORMATION_MESSAGE);
            this.jbRealizar.setEnabled(true);
            this.jcNumero.setEnabled(true);
            this.jbAbandonar.setEnabled(true);
            this.jbConsultar.setEnabled(true);
            this.jcNumero.setEnabled(true);
            this.jrPedir.setEnabled(true);
            this.jrBajarse.setEnabled(true);
        } else if (data.substring(0, 1).equalsIgnoreCase("5")) //recibe la primera carta
        {
            //this.jtCarta.setText(data.substring(1, 2) + data.substring(2)); //numero de la carta
            this.LetraCarta = data.substring(2); //letra carta

            for (int i = 0; i < todas.size(); i++) {
                if (todas.get(i).getLetra().equalsIgnoreCase(data.substring(2)) && (todas.get(i).getNumero() == Integer.parseInt(data.substring(1, 2)))) {
                    ImageIcon imagenFondoR = new ImageIcon();
                    imagenFondoR = new ImageIcon(getClass().getResource(todas.get(i).getURL()));
                    this.CartaMuestra.setIcon(imagenFondoR);
                }
            }

        } else if (data.substring(0, 1).equalsIgnoreCase("6")) //devuelve la carta siguiente
        {
            //this.jtCarta.setText(data.substring(1, 2) + data.substring(2)); //numero de la carta
            this.LetraCarta = data.substring(2); //letra carta

             for (int i = 0; i < todas.size(); i++) {
                if (todas.get(i).getLetra().equalsIgnoreCase(data.substring(2)) && (todas.get(i).getNumero() == Integer.parseInt(data.substring(1, 2)))) {
                    ImageIcon imagenFondoR = new ImageIcon();
                    imagenFondoR = new ImageIcon(getClass().getResource(todas.get(i).getURL()));
                    this.CartaMuestra.setIcon(imagenFondoR);
                }
             }
        } else if (data.substring(0, 1).equalsIgnoreCase("7")) //devuelve la carta anterior
        {
            //this.jtCarta.setText(data.substring(1, 2) + data.substring(2)); //numero de la carta
            this.LetraCarta = data.substring(2); //letra carta

             for (int i = 0; i < todas.size(); i++) {
                if (todas.get(i).getLetra().equalsIgnoreCase(data.substring(2)) && (todas.get(i).getNumero() == Integer.parseInt(data.substring(1, 2)))) {
                    ImageIcon imagenFondoR = new ImageIcon();
                    imagenFondoR = new ImageIcon(getClass().getResource(todas.get(i).getURL()));
                    this.CartaMuestra.setIcon(imagenFondoR);
                }
             }
        } else if (data.substring(0, 1).equalsIgnoreCase("8")) // cuando anfitrion baja un cuarteto
        {
            //this.jtTablero.setText(this.jcNumero.getSelectedIndex()+"\n");
            JOptionPane.showMessageDialog(null, "El anfitrion bajo un cuarteto", "INFORMACION", JOptionPane.INFORMATION_MESSAGE);
        //this.jcNumero.removeItem(data.substring(2));

        } else if (data.substring(0, 1).equalsIgnoreCase("9")) {
            this.jlTurnoActual.setText("Jugador1");
            this.jbRealizar.setEnabled(true);
            this.jrBajarse.setEnabled(true);
            this.jrPedir.setEnabled(true);
            this.jcNumero.setEnabled(true);
        } else if (data.substring(0, 2).equalsIgnoreCase("A0")) {
            JOptionPane.showMessageDialog(null, "EMPATE", "INFORMACION", JOptionPane.INFORMATION_MESSAGE);
            this.dispose();
            this.gc.setVisible(true);
        } else if (data.substring(0, 2).equalsIgnoreCase("A1")) {
            JOptionPane.showMessageDialog(null, "PERDISTE", "INFORMACION", JOptionPane.INFORMATION_MESSAGE);
            this.dispose();
            this.gc.setVisible(true);
        } else if (data.substring(0, 2).equalsIgnoreCase("A2")) {
            JOptionPane.showMessageDialog(null, "GANASTE", "INFORMACION", JOptionPane.INFORMATION_MESSAGE);
            this.dispose();
            this.gc.setVisible(true);
        } else if (data.substring(0, 2).equalsIgnoreCase("A3")) {
            JOptionPane.showMessageDialog(null, "El Anfitrión abandono la parida", "INFORMACION", JOptionPane.INFORMATION_MESSAGE);
            this.dispose();
            this.gc.setVisible(true);
            try {
                this.ij.dispose();
            } catch (Exception e) {
            }
        } else if (data.substring(0, 2).equalsIgnoreCase("A4")) //juega jugador1
        {
            this.jbRealizar.setEnabled(true);
            this.jrBajarse.setEnabled(true);
            this.jrPedir.setEnabled(true);
            this.jcNumero.setEnabled(true);
        } else if (data.substring(0, 2).equalsIgnoreCase("A5")) //juega anfitrion
        {
            this.jbRealizar.setEnabled(false);
            this.jrBajarse.setEnabled(false);
            this.jrPedir.setEnabled(false);
            this.jcNumero.setEnabled(false);
        } else if (data.substring(0, 2).equalsIgnoreCase("A6")) {
            JOptionPane.showMessageDialog(null, "No hay cartas con es numero", "INFORMACION", JOptionPane.INFORMATION_MESSAGE);
            this.jbRealizar.setEnabled(false);
            this.jrBajarse.setEnabled(false);
            this.jrPedir.setEnabled(false);
            this.jcNumero.setEnabled(false);
        } else if (data.substring(0, 2).equalsIgnoreCase("A7")) {
            JOptionPane.showMessageDialog(null, "Nueva Carta", "INFORMACION", JOptionPane.INFORMATION_MESSAGE);
            this.jbRealizar.setEnabled(true);
            this.jrBajarse.setEnabled(true);
            this.jrPedir.setEnabled(true);
            this.jcNumero.setEnabled(true);
        } else if (data.substring(0, 2).equalsIgnoreCase("A8")) // cuarteto valido
        {
            this.puntosJugador1 += 4;
            JOptionPane.showMessageDialog(null, "Nuevo Cuarteto", "INFORMACION", JOptionPane.INFORMATION_MESSAGE);
            this.jlPuntos.setText("" + this.puntosJugador1);
            this.jbRealizar.setEnabled(true);
            this.jrBajarse.setEnabled(true);
            this.jrPedir.setEnabled(true);
            this.jcNumero.setEnabled(true);
        //this.jcNumero.removeItem(data.substring(2));
        //this.jtTablero.append(this.LetraCarta);
        } else if (data.substring(0, 2).equalsIgnoreCase("A9")) {
            JOptionPane.showMessageDialog(null, "No hay cuarteto", "INFORMACION", JOptionPane.INFORMATION_MESSAGE);
            this.jbRealizar.setEnabled(false);
            this.jrBajarse.setEnabled(false);
            this.jrPedir.setEnabled(false);
            this.jcNumero.setEnabled(false);

        }
    /*else if(data.substring(0, 2).equalsIgnoreCase("A8"))
    {
    this.
    }*/
    }
}